import store from '@/store/index'
import { router } from '@/router'
import { minCache } from '@/utils/min-cache'

export function showToast(params) {
  store.commit('toast/setToastParams', params)
  store.commit('toast/setToastShow', true)
}

export async function showPositionToast() {
  return new Promise((resolve, reject) => {
    if (!minCache.get('position')?.longitude) {
      uni.showToast({
        title: '开启定位,享受精彩生活',
        icon: 'none',
        mask: true,
        duration: 3000,
        success: () => {
          setTimeout(() => {
            router.push({
              name: 'Position',
              params: {
                location: 'position',
                redirect: 'Position',
                selectedBack: router.currentRoute.name,
              },
            })
          }, 3000)
        },
      })
      reject(false)
    }
    resolve(true)
  })
}
